<?php

namespace App\Http\ControllersAdmin;

use App\Validation\AdminLoginValidation;
use App\Service\UserService;

class CommonController extends BaseController
{
    public function LoginAction()
    {
		$raw = $this->validation(new AdminLoginValidation,$this->request->getJsonRawBody());
        
        $account = UserService::getAccount($raw);
        if (!$account)
            return $this->echoJson('账号不存在');

        $user = UserService::getAccountInfo($raw);

        if (!$user)
            return $this->echoJson('用户名或密码错误');

        $session = $this->session;
        $session->set('sub', $user);
        // return $this->echoJson($user);
        return $this->echoJson(['xtoken'=>$session->write()]);
    }

    public function logoutAction()
    {
    	echo "logout";
    }
	
	public function registerAction()
	{
		echo "register";
	}
}
